//
//  HZUIDevice+Resolutions.m
//  wdEdu
//
//  Created by Khzliu on 14-9-1.
//  Copyright (c) 2014年 khzliu. All rights reserved.
//

#import "UIDevice+Resolutions.h"

@implementation UIDevice (Resolutions)


+ (UIDeviceResolution) currentResolution {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);
            if (result.height <= 480.0f)
                return UIDevice_iPhoneStandardRes;
            return (result.height > 960 ? UIDevice_iPhoneTallerHiRes : UIDevice_iPhoneHiRes);
        } else
            return UIDevice_iPhoneStandardRes;
    } else
        return (([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) ? UIDevice_iPadHiRes : UIDevice_iPadStandardRes);
}


+ (BOOL)isRunningOniPhone5{
    if ([self currentResolution] == UIDevice_iPhoneTallerHiRes) {
        return YES;
    }
    return NO;
}


+ (BOOL)isRunningOniPhone{
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
}


/********************************** new methos ***********************************************/


+ (UIDeviceResolution) screenScaleResolution {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        //iPhone的尺寸
        if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
            CGSize result = [[UIScreen mainScreen] bounds].size;
            
            double iosVersion = [[UIDevice currentDevice].systemVersion doubleValue];//判定系统版本。
            
            if (iosVersion >= 8.0) {
                CGFloat screenWidth = result.width;
                CGFloat screenHeight = result.height;
                
                UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
                if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
                    CGFloat tmp = screenWidth;
                    screenWidth = screenHeight;
                    screenHeight = tmp;
                }
                result = CGSizeMake(screenWidth, screenHeight);
            }
            
            result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);
            
            if (result.height == 2*480.0f){
                return UIDevice_iPhoneHiResThreeFive;
            }
            if (result.height == 2*568.0f) {
                return UIDevice_iPhoneHiResFour;
            }
            if (result.height == 2*667.0f) {
                return UIDevice_iPhoneHiResFourSeven;
            }
            if (result.height == 3*736.0f) {
                return UIDevice_iPhoneHiResFiveFive;
            }
        } else
            return UIDevice_iPhoneStandardRes;
    } else{
        //iPad 尺寸
        return UIDevice_iPadHiRes;
    }
    return UIDevice_UnKnownSizeScale;
}


//当前是否运行在3.5寸屏

+ (BOOL)isRunningOnInchThreeFiveScreen
{
    if ([self screenScaleResolution] == UIDevice_iPhoneHiResThreeFive) {
        return YES;
    }
    return NO;
}

// 当前是否运行在4寸屏

+ (BOOL)isRunningOnInchFourScreen
{
    if ([self screenScaleResolution] == UIDevice_iPhoneHiResFour) {
        return YES;
    }
    return NO;
}


//当前是否运行在4.7寸屏

+ (BOOL)isRunningOnInchFourSevenScreen
{
    if ([self screenScaleResolution] == UIDevice_iPhoneHiResFourSeven) {
        return YES;
    }
    return NO;
}


//当前是否运行在5.5寸屏

+ (BOOL)isRunningOnInchFiveFiveScreen
{
    if ([self screenScaleResolution] == UIDevice_iPhoneHiResFiveFive) {
        return YES;
    }
    return NO;
}


//判断系统版本
+ (UIDeviceSystemVersion) systemVersionResolution
{
    double iosVersion = [[UIDevice currentDevice].systemVersion doubleValue];//判定系统版本。
    
    if (iosVersion >= 8.0){
        return UIDevice_SystemVersionEight;
    }else if (iosVersion < 8.0 && iosVersion >= 7.0){
        return UIDevice_SystemVersionSeven;
    }else if (iosVersion <7.0 && iosVersion >= 6.0){
        return UIDevice_SystemVersionSix;
    }else{
        return UIDevice_UnKnownSysVersion;
    }
}

//系统版本是否是ios6 -----------YES：是 NO：不是----------------
+ (BOOL)iSIOS6
{
    if ([self systemVersionResolution] == UIDevice_SystemVersionSix) {
        return YES;
    }
    return NO;
}

//系统版本是否是ios7 -----------YES：是 NO：不是----------------
+ (BOOL)iSIOS7
{
    if ([self systemVersionResolution] == UIDevice_SystemVersionSeven) {
        return YES;
    }
    return NO;
}

//系统版本是否是ios8 -----------YES：是 NO：不是----------------
+ (BOOL)iSIOS8
{
    if ([self systemVersionResolution] == UIDevice_SystemVersionEight) {
        return YES;
    }
    return NO;
}
@end
